<template>
  <div class="container">
    <CustomTable ref="listRef" :columns="cols" titleIcon="icon-settings" :actions="actions" :dialogConfig="dialogConfig" isCreate tableTitle="菜单管理" :isShowPagination="false">
      <template #type="{ row, column }">
        {{ uniTypeFilter(row.type, column) }}
      </template>
      <template #mode="{ row, column }">
        {{ uniTypeFilter(row.mode, column) }}
      </template>
      <template #icon="{ row }">
        <component :is=" row.icon" style="font-size: 25px;" />
      </template>
      <template #is_basics="{ row }">
        <a-tag :color="row.is_basics === 1 ? '#00b42a' : '#86909c'">{{ row.is_basics === 1 ? '是' : '否' }}</a-tag>
      </template>
      <template #is_login="{ row }">
        <a-tag :color="row.is_login === 1 ? '#00b42a' : '#86909c'">{{ row.is_login === 1 ? '是' : '否' }}</a-tag>
      </template>
      <template #is_disable="{ row }">
        <a-tag :color="row.is_disable === 1 ? '#86909c' : '#00b42a'">{{ row.is_disable === 1 ? '禁用' : '启用' }}</a-tag>
      </template>
      <template #methods="{ row, column }">
        {{ uniTypeFilter(row.methods, column) }}
      </template>
      <template #firstOperation="{ row }">
        <a-button size="small" type="primary" @click="addSubMenu(row)" v-permission="actions.add.permission">添加</a-button>
      </template>
    </CustomTable>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, nextTick } from "vue";
import CustomTable from "@/components/custom-list/index.vue";
import { initUniTypeFilter } from "@/utils/utils";
import { useConditions, useColumns, useActions, useDialogConfig } from "./cfg";

export default defineComponent({
  path: "menu", // 导航路由地址
  name: "Menu",
  locale: "菜单管理", // 导航名称
  permissions: [], // 权限数组
  components: { CustomTable },
  setup(props, ctx) {
    const cdns = useConditions();
    const cols = useColumns();
    const actions = useActions();
    const dialogConfig = useDialogConfig();
    const listRef = ref();
    const uniTypeFilter = initUniTypeFilter(cdns).uniTypeFilter;

    const addSubMenu = function ({ id }) {
      dialogConfig.formConfig.extraFormData = { pid: id };
      nextTick(() => {
        listRef.value.createHandler();
      });
    };

    const compositeSet = function () {
      // cdns.main.concat(cdns.secondary).filter(item => item.options).map(item => item.options).forEach(item => typeList.value.push(...item));
    };

    return {
      cdns,
      cols,
      actions,
      dialogConfig,
      uniTypeFilter,
      addSubMenu,
      listRef,
    };
  },
});
</script>

<style></style>
